package com.ruoyi.business.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.business.vo.TAuditTemplateVo;
import com.ruoyi.business.service.ITAuditTemplateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 审批模板Controller
 *
 * @author Tellsea
 * @date 2024-01-26
 */
@Api(tags = "审批模板Controller")
@RestController
@RequestMapping("/business/auditTemplate")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class TAuditTemplateController extends BaseController {

    private final ITAuditTemplateService tAuditTemplateService;

    @ApiOperation("查询审批模板列表")
    @PreAuthorize("@ss.hasPermi('business:auditTemplate:list')")
    @GetMapping("/list")
    public TableDataInfo<TAuditTemplateVo> list(TAuditTemplateVo entity) {
        return tAuditTemplateService.queryList(entity);
    }

    @ApiOperation("查询审批模板所有列表")
    @GetMapping("/listAll")
    public AjaxResult listAll(TAuditTemplateVo entity) {
        return AjaxResult.success("查询成功", tAuditTemplateService.queryAll(entity));
    }

    @ApiOperation("导出审批模板列表")
    @PreAuthorize("@ss.hasPermi('business:auditTemplate:export')")
    @Log(title = "审批模板", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TAuditTemplateVo entity) {
        List<TAuditTemplateVo> list = tAuditTemplateService.queryAll(entity);
        ExcelUtil<TAuditTemplateVo> util = new ExcelUtil<>(TAuditTemplateVo.class);
        util.exportExcel(response, list, "审批模板数据");
    }

    @ApiOperation("获取审批模板详细信息")
    @PreAuthorize("@ss.hasPermi('business:auditTemplate:query')")
    @GetMapping(value = "/getInfo/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success("查询成功", tAuditTemplateService.queryById(id));
    }

    @ApiOperation("新增审批模板")
    @PreAuthorize("@ss.hasPermi('business:auditTemplate:add')")
    @Log(title = "审批模板", businessType = BusinessType.INSERT)
    @PostMapping("add")
    public AjaxResult add(@RequestBody TAuditTemplateVo entity) {
        return toAjax(tAuditTemplateService.save(entity));
    }

    @ApiOperation("修改审批模板")
    @PreAuthorize("@ss.hasPermi('business:auditTemplate:edit')")
    @Log(title = "审批模板", businessType = BusinessType.UPDATE)
    @PostMapping("edit")
    public AjaxResult edit(@RequestBody TAuditTemplateVo entity) {
        return toAjax(tAuditTemplateService.updateById(entity));
    }

    @ApiOperation("删除审批模板")
    @PreAuthorize("@ss.hasPermi('business:auditTemplate:remove')")
    @Log(title = "审批模板", businessType = BusinessType.DELETE)
	@GetMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(tAuditTemplateService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
